#include "mainwindow.h"
#include "ui_mainwindow.h"
#include<QPainter>
#include"MyPushButton.h"
#include<QDebug>
#include<QTimer>
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    //配制主场景

    //设置大小
    setFixedSize(320,588);
    //设置图标
    setWindowIcon(QIcon(":/res/Coin0001.png"));
    //设置标题
    setWindowTitle("翻金币主场景");
    //退出按钮实现
    connect(ui->actionquit,&QAction::triggered,[=](){
        this->close();
    });
    //开始按钮
    MyPushButton * startBtn=new MyPushButton(":/res/MenuSceneStartButton.png");
    //MyPushButton * startBtn=new MyPushButton(":/res/kaishi.jpg");
    startBtn->setParent(this);
    startBtn->move(this->width() * 0.5-startBtn->width()*0.5,this->height() * 0.7);

    //实例化选择关卡场景
    chooseScene=new ChooseLevelScene;

    //监听选择关卡的返回按钮的返回信号
    connect(chooseScene,&ChooseLevelScene::chooseSceneBack,this,[=](){
      chooseScene->hide();//将选择关卡场景，隐藏掉
      this->show();//重新显示主场景
    });

    connect(startBtn,&MyPushButton::clicked,[=](){
               // qDebug()<<"点击了开始";
                //做弹起特效
                startBtn->zoom1();

                startBtn->zoom2();

                //延时进入到选择关卡中
                QTimer::singleShot(500,this,[=](){



                //进入到选择关卡场景中
                //将自身隐藏
                this->hide();
                //显示选择关卡的场景
                chooseScene->show();



                });

            });
}



void MainWindow::paintEvent(QPaintEvent *)
{
    QPainter painter(this);
    QPixmap pix;
   // pix.load(":/res/PlayLevelSceneBg.png");
    pix.load(":/res/beijing.jpg");
    painter.drawPixmap(0,0,this->width(),this->height(),pix);

    //画背景上的图标
    pix.load(":/res/Title.png");

    pix=pix.scaled(pix.width()*0.7,pix.height()*0.7);

    painter.drawPixmap(10,20,pix);//coinflip


}

MainWindow::~MainWindow()
{
    delete ui;
}
